package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.BaseRegionInfo;
import com.softer.wxzj.entity.OrgRegion;
import com.softer.wxzj.service.OrgRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 小区区域绑定
 *
 * @author Gong Zhiyang
 * @date 2020/5/28
 */
@RestController
@RequestMapping("/orgRegion")
public class OrgRegionController {
    @Autowired
    private OrgRegionService orgRegionService;

    /**
     * 新增绑定小区
     *
     * @param orgRegion 绑定信息
     * @return 新增结果
     */
    @PostMapping("/addOrgRegion")
    @LogRecord(description = "新增绑定小区", operationUnit = LogOperationUnit.ORG_REGION, operationType = LogOperationType.INSERT)
    public CommonResult addOrgRegion(OrgRegion orgRegion) {
        return orgRegionService.addOrgRegion(orgRegion);
    }

    /**
     * 删除绑定小区
     *
     * @param id 绑定ID
     * @return 删除结果
     */
    @PostMapping("/deleteOrgRegion")
    @LogRecord(description = "删除绑定小区", operationUnit = LogOperationUnit.ORG_REGION, operationType = LogOperationType.DELETE)
    public CommonResult deleteOrgRegion(String id) {
        return orgRegionService.deleteOrgRegion(id);
    }

    /**
     * 查询物业绑定的小区列表
     *
     * @param page           分页信息
     * @param baseRegionInfo 查询实体
     * @return 小区列表
     */
    @PostMapping("/getOrgRegionList")
    @LogRecord(description = "查询物业绑定的小区列表", operationUnit = LogOperationUnit.ORG_REGION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseRegionInfo> getOrgRegionList(Page page, BaseRegionInfo baseRegionInfo) {
        return orgRegionService.getOrgRegionList(page, baseRegionInfo);
    }

    /**
     * 查询物业绑定的所有小区列表
     * （用于下拉菜单）
     *
     * @param operNo 登录账号
     * @return 小区列表
     */
    @PostMapping("/getAllRegion")
    public List<BaseRegionInfo> getAllRegion(String operNo) {
        return orgRegionService.getAllRegion(operNo);
    }

    /**
     * 新增管辖小区时的查询列表
     *
     * @param regionName 小区名称
     * @param zoneCode   所在区域
     * @return 小区列表
     */
    @PostMapping("/getRegionList")
    @LogRecord(description = "新增管辖小区时的查询列表", operationUnit = LogOperationUnit.ORG_REGION, operationType = LogOperationType.SELECT)
    public List<BaseRegionInfo> getRegionList(String regionName, String zoneCode) {
        return orgRegionService.getRegionList(regionName, zoneCode);
    }

}
